﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <%@ include file="../common/header.jsp" %>
    <script type="text/javascript" src="/js/My97DatePicker/WdatePicker.js"></script>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <%@ include file="../common/top.jsp" %>

    <div class="row">
        <div class="col-sm-3">
            <c:set var="menu" value="customerTraceHistory"/>
            <%@ include file="../common/menu.jsp" %>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">跟进历史管理</h1>
                </div>
            </div>
            <form class="form-inline" id="searchForm" action="/customerTraceHistory/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword"
                           value="${qo.keyword}" placeholder="请输入客户姓名">
                </div>
                <div class="form-group">
                    <label>时间:</label>
                    <input class="form-control" name="beginDate" value="<fmt:formatDate value="${qo.beginDate}" pattern="yyyy-MM-dd"/>" placeholder="请输入开始时间" type="text" readonly> ~
                    <input class="form-control" name="endDate" value="<fmt:formatDate value="${qo.endDate}" pattern="yyyy-MM-dd"/>" placeholder="请输入结束时间" type="text" readonly>
                </div>
                
                <button type="submit" class="btn btn-primary">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>编号</th>
                    <th>客户姓名</th>
                    <th>跟进时间</th>
                    <th>跟进记录</th>
                    <th>跟进方式</th>
                    <th>跟进结果</th>
                    <th>录入人</th>
                    <th>操作</th>
                </tr>
                <c:forEach var="entity" items="${pageInfo.list}" >
				 <tr>
					 <td>${entity.id}</td>
					 <td>${entity.customer.name}</td>
					 <td><fmt:formatDate value="${entity.traceTime}" pattern="yyyy-MM-dd"/></td>
					 <td>${entity.traceDetails}</td>
					 <td>${entity.type.title}</td>
					 <td>${entity.traceResultName}</td>
					 <td>${entity.inputUser.name}</td>
					 <td>
						 <a class="btn btn-info btn-xs inputBtn" data-json='${entity.json}'>
							 <span class="glyphicon glyphicon-pencil"></span>编辑
						 </a>						 
					 </td>
				 </tr>
				</c:forEach>
				 
            </table>

            <%@ include file="../common/page.jsp" %>
        </div>
    </div>
</div>

<%-- 跟进模态框 --%>
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">编辑</h4>
            </div>
            <div class="modal-body">
                <!--填充编辑界面-->
                <form class="form-horizontal" action="/customerTraceHistory/saveOrUpdate.do" method="post" id="traceForm">
                    <input type="hidden" name="id"/>
                    <input type="hidden" name="customer.id"/>
                    <div class="form-group" >
                        <label class="col-lg-4 control-label">客户姓名：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" id="customerName" readonly/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">跟进时间：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="traceTime" readonly
                                   placeholder="请输入跟进时间" onclick="WdatePicker({maxDate:new Date()});"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">跟进记录：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="traceDetails"
                                   placeholder="请输入跟进记录"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">交流方式：</label>
                        <div class="col-lg-6">
                            <select class="form-control" name="type.id">
                           	 		<c:forEach var = "t" items = "${types}">
                                    	<option value = "${t.id}">${t.title}</option>
                                    </c:forEach>
                                    <!-- <option value="9">微信</option>
                                    <option value="12">去电跟踪</option>
                                    <option value="10">营销QQ</option>
                                    <option value="11">来电咨询</option>
                                    <option value="13">短信</option> -->
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">跟进结果：</label>
                        <div class="col-lg-6">
                            <select class="form-control" name="traceResult">
                                <option value="3">优</option>
                                <option value="2">中</option>
                                <option value="1">差</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">备注：</label>
                        <div class="col-lg-6">
                            <textarea class="form-control" name="remark"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary submitBtn">保存</button>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
$(function() {
	//日历插件
	$("#searchForm input[name='beginDate']").click(function() {
		WdatePicker({
			maxDate: new Date()
		});
	});
	$("#searchForm input[name='endDate']").click(function() {
		WdatePicker({
			minDate: $("#searchForm input[name='beginDate']").val(),
			maxDate: new Date()
		});
	});
	
	//给添加和编辑按钮绑定点击事件
	$(".inputBtn").click(function() {
		//清空模态框数据
		$("#editForm input").val("");
		
		//弹出模态框
		$("#inputModal").modal("show");
		
		//回填数据 data-json
		var json = $(this).data("json");
		if (json) { //当前要编辑操做
			$("#editForm input[name='id']").val(json.id);
			$("#editForm input[name='name']").val(json.name);
			$("#editForm input[name='age']").val(json.age);
			$("#editForm input[name='tel']").val(json.tel);
			$("#editForm input[name='qq']").val(json.qq);
			$("#editForm select[name='gender']").val(json.gender);
			$("#editForm select[name='job.id']").val(json.jobId);
            $("#editForm select[name='source.id']").val(json.sourceId);
		}
	});
	
	//给保存按钮绑定点击事件
	$(".submitBtn").click(function() {
		//提交表单
		$("#editForm").submit();
	});
	//编辑按钮
	$(".inputBtn").click(function() {
		//弹出模态框
		$("#traceModal").modal("show");
		var json = $(this).data("json");
		console.log(json);
		//回显客户姓名
		$("#traceForm input[name='id']").val(json.id);
		$("#customerName").val(json.customerName);
		$("#traceForm input[name='customer.id']").val(json.customerId);
		$("#traceForm input[name='traceDetails']").val(json.traceDetails);
		$("#traceForm input[name='traceTime']").val(json.traceTime);
		$("#traceForm select[name='type.id']").val(json.typeId);
		$("#traceForm select[name='traceResult']").val(json.traceResult);
		$("#traceForm textarea[name='remark']").val(json.remark);
		$("#traceForm textarea[name='inputUser.id']").val(json.inputUserId);
	});
	
	$(".submitBtn").click(function() {
		$("#traceForm").submit();
	});
});
</script>
</body>
</html>